package com.math;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collection;

public class FileNewLineUtil {

    public static void main(String[] args) throws IOException {


        String source = "D:\\dev\\docx4j\\documents4j-documents4j-1.1.9";
        String dest = "D:\\dev\\docx4j\\documents4j-documents4j-1.1.9-dest";
        Collection<File> files = FileUtils.listFiles(new File(source), null, true);

        File file1 = new File(dest);
        if (!file1.exists()) {
            file1.mkdirs();
        }
        for (File file : files) {
            String path = file.getPath();
            System.out.println(path);

            String replace = path.replace(source, dest);

            File tmpFile = new File(replace);
            if (!tmpFile.getParentFile().exists()) {
                tmpFile.getParentFile().mkdirs();
            }
            String s = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
            if (!s.contains("\r")) {
                s = s.replace("\n", "\r\n");
            }
            FileUtils.write(tmpFile,s,StandardCharsets.UTF_8);

            System.out.println("path2=" + replace);
        }


    }
}
